<?php
	$tplPro = new XTemplate('view/product/list.htm');
	$sql = "SELECT * FROM tblproduct WHERE 1=1";
	$products = $db->fetchAll($sql);
	$limit 		= 12;
	$page		= (_POST('pi'))?_POST('pi'):1;
	$offset		= ($page-1)*$limit;
	$totalRow 	= count($products);
	$sql = "SELECT * FROM tblproduct WHERE 1=1  ORDER BY product_id DESC LIMIT $offset,$limit";
	$products = $db->fetchAll($sql);
	foreach ($products as $product) {
		$sql = "SELECT * FROM tblproduct_img WHERE 	product_id = ".$product['product_id'];
		$images = $db->fetchAll($sql);
		foreach($images as $image){
			if($image['basic_img']==1){
				$product['image'] = "<img src='$baseUrl".$image['img_url']."' title='".$image['img_label']."' width='84px' height='98px' />";
			}
		}
		$sql = "SELECT category_name FROM tblcategory WHERE 	category_id = ".$product['category_id'];
		$category = $db->fetchOne($sql);
		$product['category_id'] = $category['category_name'];
		$product['createddate'] = date("H:i:s d-m-Y", strtotime($product['createddate']));
		$tplPro->insert_loop('list.listpro', array('listpro'=>$product));
	}
	if ( count($products)==0 ) {
		$tplPro->parse('list.norecord');
	}
	$pages = pagenavigator($page, $totalRow, $limit, 5, "$baseUrl/admin/?c=product&a=list");
	$tplPro->assign('pages', $pages);
	$tplPro->parse('list');
	$content = $tplPro->text('list');
?>